package com.OA.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.OA.dao.ZZH_EmailMapper;
import com.OA.entity.Message;
import com.OA.entity.User;
import com.OA.service.ZZH_EmailService;
import com.OA.util.Page;
/**
 * 站内信实现层
 * @author z_z_h
 *
 */
@Service
public class ZZH_EmailServiceImpl implements ZZH_EmailService{

	@Autowired
	private ZZH_EmailMapper emialMapper;

	/**
	 * 获取下拉列表的用户名
	 * @return
	 */
	@Transactional(readOnly = true)
	@Override
	public List<User> optionByuserName() {	
		return emialMapper.optionByuserName();
	}

	/**
	 * 用于登录用户
	 * @return
	 */
	@Transactional(readOnly = true)
	@Override
	public Message login(String userName) {
		return emialMapper.login(userName);
	}
	/**
	 * 添加到草稿箱/发送邮件
	 */
	@Transactional(readOnly = false)
	@Override
	public void draftAndOutBox(Message message) {
		emialMapper.draftAndOutBox(message);
	}
	/**
	 * 查询所有草稿箱及按条件查询草稿箱/查询所有发件箱及按条件查询发件箱
	 * @param map
	 * @return
	 */
	@Transactional(readOnly = true)
	@Override
	public Page<Message> loadDraftAndOutBox(Map map) {
		List<Message> list = emialMapper.loadDraftsAndOutBox(map);
		int total = emialMapper.loadDraftsAndOutBoxByTotal(map);
		Page<Message> page = new Page<Message>((int)map.get("pageNo"), (int)map.get("pageSize"), total, list);
		return page;
	}
	/**
	 * 删除数据
	 * @param mid
	 */
	@Transactional(readOnly = false)
	@Override
	public void deleteById(Integer mid) {
		emialMapper.deleteById(mid);
	}
	/**
	 * 恢复数据
	 * @param mid
	 */
	@Transactional(readOnly = false)
	@Override
	public void recoverById(Integer mid) {
		emialMapper.recoverById(mid);
	}
	/**
	 * 查询所有收件箱及按条件查询收件箱
	 * @param map
	 * @return
	 */
	@Transactional(readOnly = true)
	@Override
	public Page<Message> loadInBox(Map map) {
		List<Message> list = emialMapper.loadInBox(map);
		int total = emialMapper.loadInBoxByTotal(map);
		Page<Message> page = new Page<Message>((int)map.get("pageNo"), (int)map.get("pageSize"), total, list);
		return page;
	}
	/**
	 * 根据用户发件人或者收件人名字查询id
	 * @param userName
	 * @return
	 */
	@Transactional(readOnly = true)
	@Override
	public List<Message> loginById(String userName) {
		return emialMapper.loginById(userName);
	}
	/**
	 * 添加到回收站
	 * @param mid
	 */
	@Transactional(readOnly = false)
	@Override
	public void insertRecycleStand(Integer mid) {
		emialMapper.insertRecycleStand(mid);
	}
	/**
	 * 回收站查询所有发件箱
	 * @param map
	 * @return
	 */
	@Transactional(readOnly = true)
	@Override
	public Page<Message> selectRecycleOutBox(Map map) {
		List<Message> list = emialMapper.selectRecycleOutBox(map);
		int total = emialMapper.selectRecycleOutBoxByTotal(map);
		Page<Message> page = new Page<Message>((int)map.get("pageNo"), (int)map.get("pageSize"), total, list);
		return page;
	}
	/**
	 * 回收站查询所有收件箱
	 * @param map
	 * @return
	 */
	@Transactional(readOnly = true)
	@Override
	public Page<Message> selectRecycleInBox(Map map) {
		List<Message> list = emialMapper.selectRecycleInBox(map);
		int total = emialMapper.selectRecycleInBoxByTotal(map);
		Page<Message> page = new Page<Message>((int)map.get("pageNo"), (int)map.get("pageSize"), total, list);
		return page;
	}
	/**
	 * 根据id查询收件箱数据进行表单回填
	 * @param mid
	 * @return
	 */
	@Override
	public Message inBoxById(int mid) {
		return emialMapper.inBoxById(mid);
	}
	/**
	 * 根据id改变已读状态
	 * @param mid
	 * @return
	 */
	@Override
	public void inBoxByIdState(int mid) {
		emialMapper.inBoxByIdState(mid);
	}	
}
